<template>
	<view class="order-pages" :style="{background:pageColor}">
		<scroll-view scroll-y class="scroll" :style="{ height: `calc(100vh - ${headerHeight}px)` }"
			:scroll-top="scrollTop" :scroll-into-view="scrollIntoView" scroll-with-animation @scroll="onScroll">
			<view class="warp">
				<view class="related-money">
					<view class="evaluation-box">
						<view class="evaluation-box-left">
							<image class='' src="https://www.peikangbao.cn/attachment/image/666/25/11/ec4595e1b7534889b6480f2b6bb75bdb.png"></image>
							<text class="ml7">非常不满意</text>
						</view>
						<view class="evaluation-box-left">
							<text class="mr7">非常满意</text>
							<image class='' src="http://www.peikangbao.cn/attachment/image/666/25/11/b871e1f3d3b64f58ae5f0b4710448484.png"></image>
						</view>
					</view>
					<view class="evaluation-list">
						<view class="evaluation-item" :class="item.active ? 'active' : ''"
							v-for="(item,index) in navList" :key="index" @click="evaluationClick(index)">{{ item.num }}
						</view>
					</view>
				</view>
				<view class="order-box">
					<view class="order-box-title">聊聊本次服务的感受，您的评价能帮助到其他人哦</view>
					<view class="order-box-text">
						<textarea class="evaluation-text" v-model="text" maxlength="-1"></textarea>
					</view>
					<view class="order-box-bottom">祝您生活愉快！</view>
				</view>
				<view class="btn-box">
					<view class="order-btn" @click="toCollect">提交评价</view>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import {
		mapState,
		mapActions,
		mapMutations
	} from "vuex"
	import $util from "@/utils/index.js"
	export default {
		components: {

		},
		data() {
			return {
				navList: [{
					num: 1,
					active: true
				}, {
					num: 2,
					active: false
				}, {
					num: 3,
					active: false
				}, {
					num: 4,
					active: false
				}, {
					num: 5,
					active: false
				}, {
					num: 6,
					active: false
				}, {
					num: 7,
					active: false
				}, {
					num: 8,
					active: false
				}, {
					num: 9,
					active: false
				}, {
					num: 10,
					active: false
				}],
				isLoad: false,
				options: {},
				text: '',
				star: 0,
				lockTap: false
			}
		},
		computed: mapState({
			configInfo: state => state.config.configInfo,
		}),
		async onLoad(options) {
			this.$util.setNavigationBarColor({
				bg: this.primaryColor
			})
			this.options = options
		},
		methods: {
			onScroll(event) {
				let top = event.detail.scrollTop
				// 楼层的吸顶设置
				this.onScrollTop = top
				// 滚动加载
				// this.getDomData(top)
			},
			evaluationClick(index) {
				this.navList.forEach((element, i) => {
					if (i <= index) {
						element.active = true
					} else {
						element.active = false
					}
				});
				this.star = index + 1
			},
			async toCollect() {
				let {
					options,
					star,
					text
				} = this
				let {
					id: order_id
				} = options
				if (!star) {
					this.$util.showToast({
						title: '请选择总体评价星级'
					})
					return
				}
				if (!text) {
					this.$util.showToast({
						title: '请输入评价内容'
					})
					return
				}
				let lable = []
				let service_star = []
				let param = {
					order_id,
					star,
					service_star,
					text,
					lable
				}
				if (this.lockTap) return
				this.lockTap = true
				this.$util.showLoading()
				try {
					await this.$api.order.addComment(param)
					this.$util.hideAll()
					this.$util.showToast({
						title: `评论成功`,
					});
					setTimeout(() => {
						this.lockTap = false
						this.$util.back()
						this.$util.goUrl({
							url: 1,
							openType: `navigateBack`
						})
					}, 500)
				} catch (e) {
					setTimeout(() => {
						this.lockTap = false
						this.$util.hideAll()
					}, 500)
				}
			}
		}
	}
</script>


<style lang="scss">
	.warp {
		background-color: #fff;
		// border-top-left-radius: 20rpx; 
		// border-top-right-radius: 20rpx; 
		overflow: hidden;

		.related-money {
			height: 160rpx;
			background: #6EC2B0;
			border-radius: 0px 0px 30rpx 30rpx;
			padding: 0 20rpx;
			overflow: hidden;

			.evaluation-box {
				// width: 650rpx;
				height: 45rpx;
				margin: 33rpx auto 0;
				padding: 7rpx 5rpx;
				padding: 0 30rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;

				.evaluation-box-left {
					display: flex;
					align-items: center;

					image {
						width: 30rpx;
						height: 30rpx;
					}

					text {
						font-family: Source Han Sans, Source Han Sans;
						font-weight: 400;
						font-size: 18rpx;
						color: #FFFFFF;
					}
				}
			}

			.evaluation-list {
				display: flex;
				align-items: center;
				justify-content: space-between;
				margin-top: 10rpx;
				padding: 0 30rpx;

				.evaluation-item {
					width: 30rpx;
					height: 40rpx;
					text-align: center;
					line-height: 40rpx;
					font-family: Source Han Sans, Source Han Sans;
					font-weight: 400;
					font-size: 18rpx;
					color: #6EC2B0;
					background: #FFFFFF;
					border-radius: 5rpx;
				}

				.active {
					color: #FFFFFF;
					background: #FF895C;
				}
			}

			.ml7 {
				margin-left: 7rpx;
			}

			.mr7 {
				margin-right: 7rpx;
			}
		}

		.order-box {
			padding: 0 50rpx;
			margin-top: 37rpx;

			.order-box-title {
				height: 36rpx;
				font-family: Source Han Sans, Source Han Sans;
				font-weight: 400;
				font-size: 24rpx;
				color: #9E9E9E;
				margin: 50rpx 0rpx 44rpx 0rpx;
			}

			.order-box-text {
				border: 1rpx solid #C4C4C4;
				border-radius: 20rpx;

				.evaluation-text {
					min-height: 800rpx;
					width: 620rpx;
					padding: 20rpx;
					font-size: 24rpx;
					color: #9E9E9E;
				}
			}

			.order-box-bottom {
				font-family: Source Han Sans, Source Han Sans;
				font-weight: 400;
				font-size: 24rpx;
				color: #9E9E9E;
				text-align: right;
				margin: 43rpx 0rpx;
			}
		}

		.btn-box {
			padding: 60rpx 0;
			display: flex;
			align-items: center;
			justify-content: center;

			.order-btn {
				width: 300rpx;
				height: 64rpx;
				background: #6EC2B0;
				border-radius: 32rpx 32rpx 32rpx 32rpx;
				font-family: Source Han Sans, Source Han Sans;
				font-weight: 400;
				font-size: 30rpx;
				color: #FFFFFF;
				text-align: center;
				line-height: 64rpx;
			}
		}
	}
</style>